package com.tr.rentcar.controller.houtai.car;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.common.StringUtils;
import com.tr.rentcar.model.bean.CarBrand;
import com.tr.rentcar.model.dao.CarBrandDao;

@WebServlet("/carbrandmodify")
public class CarBrandModifyControllor extends HttpServlet {
	Integer id;
	CarBrandDao CarBrandDao = new CarBrandDao();
	CarBrand CarBrand = new CarBrand();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			String pid=req.getParameter("pid");
			//System.out.println(pid);
			req.setAttribute("pid", pid);
			String rid = req.getParameter("id");
			if (!StringUtils.isEmpty(rid)) {
				id = Integer.parseInt(rid);
				CarBrand CarBrand = CarBrandDao.findbyid(id);
				req.setAttribute("CarBrand", CarBrand);
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		req.getRequestDispatcher("/WEB-INF/jsp/houtai_Carbrandmodify.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			req.setCharacterEncoding("utf-8");
			resp.setContentType("application/json;charset=utf-8");
			CarBrand CarBrand = CarBrandDao.findbyid(id);
			//System.out.println(CarBrand);
			PrintWriter out = resp.getWriter();
			out.print(JSONArray.toJSONString(CarBrand));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
